package com.px.biz.controller;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.px.common.utils.IdUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.px.common.constant.Constants;
import com.px.common.controller.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.px.biz.domain.DistrictRegisterDO;
import com.px.biz.service.DistrictRegisterService;
import com.px.common.utils.PageUtils;
import com.px.common.utils.R;

/**
 * 卫生区域登记
 * 
 * @author 品讯科技
 * @email zly@hnpinxun.cn
 * @date 2024-08
 */
 
@Controller
@RequestMapping("/biz/districtRegister")
public class DistrictRegisterController extends BaseController {
	@Autowired
	private DistrictRegisterService districtRegisterService;
    private String prefix = "biz/districtRegister";
	@GetMapping()
	@RequiresPermissions("biz:districtRegister:districtRegister")
	String DistrictRegister(){
	    return prefix+"/districtRegister";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("biz:districtRegister:districtRegister")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        startPage();
        List<DistrictRegisterDO> list =  districtRegisterService.list(params);
        PageUtils dataTable = getDataTable(list);
        return dataTable;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("biz:districtRegister:add")
	String add(){
	    return prefix+"/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("biz:districtRegister:edit")
	String edit(@PathVariable("id") String id,Model model){
		DistrictRegisterDO districtRegister = districtRegisterService.get(id);
		model.addAttribute("districtRegister", districtRegister);
	    return prefix+"/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("biz:districtRegister:add")
	public R save( DistrictRegisterDO districtRegister){
		districtRegister.setId(IdUtil.getStrId());
		districtRegister.setCreateUser(getUserId());
		districtRegister.setCreateTime(new Date());
		districtRegister.setUpdateUser(getUserId());
		districtRegister.setUpdateTime(new Date());
		if(districtRegisterService.save(districtRegister)){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("biz:districtRegister:edit")
	public R update( DistrictRegisterDO districtRegister){
		districtRegister.setUpdateUser(getUserId());
		districtRegister.setUpdateTime(new Date());
		districtRegisterService.updateById(districtRegister);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("biz:districtRegister:remove")
	public R remove( String id){

		DistrictRegisterDO data=districtRegisterService.getById(id);
        data.setDelFlag(Constants.DELETE_FLAG);
        if(districtRegisterService.updateById(data)){
            return R.ok();
        }
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("biz:districtRegister:batchRemove")
	public R remove(@RequestParam("ids[]") String[] ids){
		DistrictRegisterDO data=new DistrictRegisterDO();
        data.setDelFlag(Constants.DELETE_FLAG);
		districtRegisterService.update(data,new LambdaQueryWrapper<DistrictRegisterDO>().in(DistrictRegisterDO::getId,ids));
		return R.ok();
	}
	
}
